package cn.com.action;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import javax.swing.JOptionPane;
import cn.com.view.MainFrame;
import db.JDBConnection;
import db.OracleConnt;

/**
 * 按钮事件
 * 
 * @author Administrator
 * 
 */
public class BoolBarAction implements ActionListener {
	private MainFrame frame;
	
	public BoolBarAction(MainFrame frame) {
		this.frame = frame;
	}

	/**
	 * 单击按钮执行相应的方法
	 */
	public void actionPerformed(ActionEvent e) {
 		String title = e.getActionCommand();
		if ("确定".equals(title)) {
			OracleConnt oracle=OracleConnt.getOracleConnt();//oracle 连接
			String startDate=frame.getStartDate().getText().trim();
			String endDate=frame.getEndDate().getText().trim();
			if("".equals(startDate) || "".equals(endDate)){
				JOptionPane.showConfirmDialog(frame.getContentPane(), "日期不能为空！", "提示",
						JOptionPane.YES_NO_OPTION);
				return;
			}
			int count=oracle.getCount(startDate, endDate);//查看是否已导入数据
			if (count > 0) {
				int info = JOptionPane.showConfirmDialog(frame.getContentPane(), "数据已导入，是否重新导入？", "提示",
						JOptionPane.YES_NO_OPTION);
				if (info == JOptionPane.YES_OPTION) {
					oracle.deleteDate(startDate, endDate);// 删除数据
					JDBConnection sqlServer = JDBConnection.getSqlServer();
					int upcount = sqlServer.insterDate(startDate, endDate);
					if (upcount > 0) {
						int sms = JOptionPane.showConfirmDialog(frame.getContentPane(), "成功导入"+upcount+"条记录 ！", "提示",
								JOptionPane.YES_NO_OPTION);
					}
				} else if (info == JOptionPane.NO_OPTION) {
					System.out.println(JOptionPane.OK_OPTION + "取消");
				}
			}else{
				//导入数据
				JDBConnection sqlServer = JDBConnection.getSqlServer();
				int upcount = sqlServer.insterDate(startDate, endDate);
				if (upcount > 0) {
					int sms = JOptionPane.showConfirmDialog(frame.getContentPane(), "成功导入"+upcount+"条记录！", "提示",
							JOptionPane.YES_NO_OPTION);
				}
			}
		} else if ("取消".equals("取消")) {
			System.exit(0); 
		}

	}

}
